Skip to content

Fix incorrect reduction condition in fused_scatter_reduce Triton kernel#638

Open
Umang-projects wants to merge 4 commits intopyg-team:masterfrom
Umang-projects:fix-scatter-reduce-bug
Open

Fix incorrect reduction condition in fused_scatter_reduce Triton kernel#638
Umang-projects wants to merge 4 commits intopyg-team:masterfrom
Umang-projects:fix-scatter-reduce-bug

Conversation

@Umang-projects
Copy link
Copy Markdown

Description

While reviewing the Triton implementations for fused_scatter_reduce, I noticed a copy-paste error in the REDUCE1 block of _fused_scatter_reduce_forward_kernel.

Specifically, when REDUCE1 is evaluated for min or max, the kernel incorrectly checks REDUCE2 == 3 and REDUCE3 == 4 instead of REDUCE1. This causes silent mathematical errors and failing reductions when multiple reduction types (including min/max) are passed in specific orders.

Changes Made:

  • Fixed the condition inside if REDUCE1 > 0: to correctly check REDUCE1 == 3 (min) and REDUCE1 == 4 (max).

Note: I also noticed the TODOs regarding double computation of sum/mean, unrolling the loops (since tl.static_unroll is now available), and adding backward passes. I plan to address those optimizations in follow-up PRs once this critical fix is merged.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 58.40%. Comparing base (bdee3ae) to head (02aca8a).
⚠️ Report is 165 commits behind head on master.

❌ Your project check has failed because the head coverage (58.40%) is below the target coverage (80.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff             @@
##           master     #638       +/-   ##
===========================================
- Coverage   70.13%   58.40%   -11.74%     
===========================================
  Files          37       72       +35     
  Lines        1671     3236     +1565     
  Branches        0      262      +262     
===========================================
+ Hits         1172     1890      +718     
- Misses        499     1344      +845     
- Partials        0        2        +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Umang-projects
Copy link
Copy Markdown
Author

Hi @rusty1s ,
I was looking into the Triton kernel implementations and noticed a small bug part in the fused_scatter_reduce logic that wa marked as a TODO.
I have fixed the incorrect reduction conditions. Could you please review this when you have some time?

(Note: The Codecov check is failing due to overall target coverage, but the modified lines are fully covered).

Let me know if i need to make any changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant